IOUtils

object IOUtils

Functions

Link copied to clipboard
fun copy(src: File, dest: File)
Link copied to clipboard

Copy everything in the source folder to the destination directory. Does not copy the src directory itself, only the content.

Link copied to clipboard
fun copyFile(fromFile: File, toFile: File)

Copy the contents of fromFile to toFile.

Link copied to clipboard
fun copyFolder(src: File?, dest: File?)

Copy the contents of a folder into another.

Link copied to clipboard

Copy all of the bytes from one inputstream to another, returning the number of bytes copied. This does not close or flush the streams when finished.

Link copied to clipboard
Link copied to clipboard
fun delete(file: File)
Link copied to clipboard

Delete a file immediately. If the operation doesn't succeed, try to delete it on exit.

Link copied to clipboard

Delete recursively a directory and all its content.

Link copied to clipboard
fun getUnusedFileNameWithBaseAndExtension(containerFolder: File?, baseName: String, extension: String): File

Return a unique, non-existent file with the given name and name and file extension. This will name files filename.extension, filename 2.extension, filename 3.extension, etc.

Link copied to clipboard

Returns whether a directory is empty or not.

Link copied to clipboard
fun openZip(fileToOpen: File?, path: String): String?

Unzip a file in given path. Returns file parent, which is useful in dealing with backup files.

Link copied to clipboard
fun readFileFully(filename: String): ByteArray?

Reads and returns the all of the bytes from the given filename

Link copied to clipboard
fun readFully(file: File): ByteArray?

Reads and returns the all of the bytes from the given file

Read the entire contents of the given stream into a byte array. This will close the inputstream when finished, so no need to clean up after yourself.

Link copied to clipboard

Read a single line from the given InputStream, assuming the text is UTF-8 encoded. Returns null if an EOF is found before a newline character.

Link copied to clipboard
fun readlines(input: BufferedSource): List<String>

Return a list containing the lines read from the given UTF8-encoded InputStream. This will close the inputstream when finished, so no need to clean up after yourself.

Link copied to clipboard
fun renameFilesMatching(oldName: String, newName: String, dir: File)

This method will rename files matching oldName to newName in the given dir

Link copied to clipboard
fun renameMostlyAtomicallyWithoutNIO(oldFilePath: File, destFilePath: File)
Link copied to clipboard
fun unzip(input: InputStream?, destinationFolder: File?): Boolean

Unzip a zip file from the given input stream and into the given folder. Returns true if the unzipping process was successful.

Link copied to clipboard
fun writeAtomically(dataToWrite: ByteArray, outputFile: File)

Atomically write the given data to the outputFile. This works by first writing to a temporary file and then using the File.rename() method to atomically move that file into place. It is a good idea to put a synchronized block around any code that calls this for the same file.

fun writeAtomically(stringToWrite: String, outputFile: File)

Atomically write the given string to the outputFile in UTF8. This works by first writing the UTF-8 converted bytes to a temporary file and then using the File.rename() method to atomically move that file into place. It is a good idea to put a synchronized block around any code that calls this for the same file.

Link copied to clipboard
fun zipRecursively(zipOut: ZipOutputStream, fileToZip: File, filter: FilenameFilter?)

Recursively zip the given file or directory, only adding files matching the filter (if any).